home *** CD-ROM | disk | FTP | other *** search
- Path: hubcap.clemson.edu!hubcap!mjs
- From: mjs@hubcap.clemson.edu (M. J. Saltzman)
- Newsgroups: comp.lang.c
- Subject: Re: Float calculations
- Date: 1 Feb 96 21:41:18 GMT
- Organization: Clemson University
- Message-ID: <mjs.823210878@hubcap>
- References: <4eqssf$d9q@camelot.ccs.neu.edu>
- NNTP-Posting-Host: hubcap.clemson.edu
-
- jason@ccs.neu.edu (Jason Leatherman) writes:
-
-
- >Hi,
-
- > Check out the results I get when running this simple program on a
- >Sparc/UNIX system, compiled with gcc:
-
- >#include <stdio.h>
-
- >void main()
-
- That's "int main()" to you.
-
- >{
- > float a, b;
-
- > printf("%0.10f %0.10f %0.10f\n", 99974.0, 50.0, 99974.0/50.0);
-
- Floating-point constants that are not suffixed with 'f' are doubles,
- so the result of the division is a double.
-
- > a = 99974.0;
- > b = 50.0;
- > printf("%0.10f %0.10f %0.10f\n", a, b, a/b);
-
- Both a and b are float, so the result of the division a float, which is
- then promoted to double to pass to printf().
-
- Don't forget to
-
- return 0;
-
- >}
-
- >The output is:
- >99974.0000000000 50.0000000000 1999.4800000000
- >99974.0000000000 50.0000000000 1999.4799804688
-
- > Why do the divisions produce different results? This is probably some
- >simple thing that I've forgotten, but I haven't figured it out yet. Does
- >anyone know? Note that compiling with the -ffloat-store flag didn't make
- >a difference.
-
- It's not immediately obvious that it should make a difference.
-
- > Thanks for any help,
-
- >Jason
- --
- Matthew Saltzman
- Clemson University Math Sciences
- mjs@clemson.edu
-